package com.xdty.fastInput.utils;

import javax.swing.*;
import javax.swing.table.TableModel;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: BaiShiSheng
 * @Create: 2024/12/11/11:34
 */
public class JFrameUtil {
    public static final Toolkit toolkit = Toolkit.getDefaultToolkit();
    public static final Dimension displaySize = toolkit.getScreenSize();

    public static int getDisplayHeight(){
        return displaySize.height;
    }

    public static int getDisplayWidth(){
        return displaySize.width;
    }

    public static JFrame createWindow(String title,int width, int height){
        JFrame jFrame = new JFrame(title);
        int x = getDisplayWidth()-(width*2);
        int y = getDisplayHeight()-height;
        jFrame.setBounds(500, 300, width, height);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        return jFrame;
    }

    public static List<Object[]> getAllTableData(TableModel tableModel){
        int rowCount = tableModel.getRowCount();
        int columnCount = tableModel.getColumnCount();
        List<Object[]> data = new ArrayList<>();
        for (int row = 0; row < rowCount; row++) {
            Object[] rowData = new Object[columnCount];
            for (int col = 0; col < columnCount; col++) {
                rowData[col] = tableModel.getValueAt(row, col);
            }
            data.add(rowData);
        }
        return data;
    }

    public static Object[] getTableDataByRow(TableModel tableModel,int row){
        int columnCount = tableModel.getColumnCount();
        Object[] rowData = new Object[columnCount];
        for (int col = 0; col < columnCount; col++) {
            rowData[col] = tableModel.getValueAt(row, col);
        }
        return rowData;
    }

    public static Object getTableDataByColumn(TableModel tableModel,int row,int column){
        return tableModel.getValueAt(row, column);
    }
}
